package com.segersten.othello.service.akka.game;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.xml.bind.annotation.XmlRootElement;

import com.segersten.othello.model.Color;
import com.segersten.othello.model.Point;

@XmlRootElement
public class BoardState2 {

	private int round;
	private Color nextColor;
	private List<Action> transform;
	private Set<Point> availablePoints;
	private int playerBlackPoints;
	private int playerWhitePoints;
	
	public BoardState2() {
	}

	public BoardState2(int playerBlackPoints, int playerWhitePoints, 
			int round, Color nextColor, List<Action> transform,
			Set<Point> availablePoints) {
		this.playerBlackPoints = playerBlackPoints;
		this.playerWhitePoints = playerWhitePoints;
		this.nextColor = nextColor;
		this.transform = transform;
		this.availablePoints = availablePoints;
		this.round = round;
	}

	public Color getNextColor() {
		return nextColor;
	}

	public List<Action> getTransform() {
		return transform;
	}

	public Set<Point> getAvailablePoints() {
		return (availablePoints==null)?new HashSet<Point>():availablePoints;
	}

	public int getRound() {
		return round;
	}

	public void setRound(int round) {
		this.round = round;
	}

	public void setNextColor(Color nextColor) {
		this.nextColor = nextColor;
	}

	public void setTransform(List<Action> transform) {
		this.transform = transform;
	}

	public void setAvailablePoints(Set<Point> availablePoints) {
		this.availablePoints = availablePoints;
	}

	public int getPlayerBlackPoints() {
		return playerBlackPoints;
	}

	public void setPlayerBlackPoints(int playerBlackPoints) {
		this.playerBlackPoints = playerBlackPoints;
	}

	public int getPlayerWhitePoints() {
		return playerWhitePoints;
	}

	public void setPlayerWhitePoints(int playerWhitePoints) {
		this.playerWhitePoints = playerWhitePoints;
	}

	
	@Override
    public String toString()
    {
        return "BoardState2 [round=" + round + ", nextColor=" + nextColor + ", transform=" + transform
                + ", availablePoints=" + availablePoints + ", playerBlackPoints=" + playerBlackPoints
                + ", playerWhitePoints=" + playerWhitePoints + "]";
    }

    @Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((availablePoints == null) ? 0 : availablePoints.hashCode());
		result = prime * result
				+ ((nextColor == null) ? 0 : nextColor.hashCode());
		result = prime * result
				+ ((transform == null) ? 0 : transform.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BoardState2 other = (BoardState2) obj;
		if (availablePoints == null) {
			if (other.availablePoints != null)
				return false;
		} else if (!availablePoints.equals(other.availablePoints))
			return false;
		if (nextColor != other.nextColor)
			return false;
		if (transform == null) {
			if (other.transform != null)
				return false;
		} else if (!transform.equals(other.transform))
			return false;
		return true;
	}

	public BoardState2 subset(int round) {
		if (round > transform.size()) {
			throw new IllegalArgumentException(String.format(
					"Round (%d) larger that transform list (%d)", round,
					transform.size()));
		}
		return new BoardState2(playerBlackPoints, playerWhitePoints, transform.size(), nextColor, transform.subList(
				round, transform.size()), availablePoints);
	}

}
